package com.briup.jd2407cms.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.briup.jd2407cms.domain.Article;
import com.briup.jd2407cms.domain.extend.ArticleExtend;
import com.briup.jd2407cms.domain.extend.ArticleParam;
import com.briup.jd2407cms.result.Result;
import com.briup.jd2407cms.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @BelongsProject: cms2
 * @BelongsPackage: com.briup.jd2407cms.web.controller
 * @Author: wangjie
 * @CreateTime: 2024-11-22  09:23
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@Api(tags = "资讯模块")
@RequestMapping("/auth/article")
public class ArticleController {
    @Autowired
    ArticleService articleService;
    @ApiOperation("添加或修改文章")
    @PostMapping("/saveOrUpdate")
    private Result saveOrUpdate(@RequestBody Article article, HttpServletRequest request){
        articleService.addOrEdit(article,request);
        return Result.success();
    }
    @ApiOperation("审核文章")
    @PutMapping("/review")
    private Result review(Long id,String status){
        articleService.reviewArticle(id,status);
        return Result.success("审核完成");
    }
    @ApiOperation("分页条件查询")
    @PostMapping("/query")
    private Result query(@RequestBody ArticleParam articleParam){
        IPage<ArticleExtend> query = articleService.query(articleParam);
        return Result.success(query);
    }
    @ApiOperation("查询指定文章")
    @GetMapping("/queryById/{id}")
    private Result queryById(@PathVariable Long id){
        ArticleExtend articleExtend = articleService.queryById(id);
        return Result.success(articleExtend);
    }
    @ApiOperation("删除文章")
    @DeleteMapping("/deleteByBatch/{ids}")
    private Result deleteByBatch(@PathVariable List<Long> ids){
        articleService.deleteByBatch(ids);
        return Result.success();
    }

}
